<?php

namespace App\Modules\Admin\Http\Controllers;

use App\Exceptions\ValidationException;
use App\Http\Controllers\BaseController;
use App\Modules\Admin\Services\ActivityService;
use Illuminate\Http\Request;

class ActivityController extends BaseController
{
    public function __construct(ActivityService $activityService)
    {
        $this->middleware('check.adminLogin')->except('index');

        $this->activityService = $activityService;
    }

    public function index()
    {
        $param = [];
        $data = $this->activityService->getList($param);

        return $this->response->success($data);
    }

    public function getActivityName()
    {
        $data = $this->activityService->getAllActivityName();

return $this->response->success($data);

    }

    public function show($id)
    {
        if (!$id) {
            throw new ValidationException('缺失参数');
        }

        $result = $this->activityService->getInfo($id);

        return $this->response->success($result);
    }

    public function store(Request $request)
    {
        $param = $this->validationParameter([
            'title|标题' => 'require',
            'content|内容' => 'require',
            'image|封面图' => 'require',
            'sign_up_start|开始报名时间' => 'require',
            'sign_up_end|结束报名时间' => 'require',
            'activity_time_start|开始活动时间' => 'require',
            'activity_time_end|结束活动时间' => 'require',
            'address|活动地址' => 'require',
            'limit_count|人数限制' => 'require',
            'limit_age|年龄限制' => 'require',
            'cost|活动费用' => 'require',
        ]);

        $param['publisher_uid'] = $request->user()->admin_uid ?? null;

        $result = $this->activityService->add($param);

        return $this->response->success($result);
    }

    public function update(Request $request)
    {
        $id = $request->input('id');
        $param = $this->validationParameter([
            'title|标题' => 'require',
            'content|内容' => 'require',
            'image|封面图' => 'require',
            'sign_up_start|开始报名时间' => 'require',
            'sign_up_end|结束报名时间' => 'require',
            'activity_time_start|开始活动时间' => 'require',
            'activity_time_end|结束活动时间' => 'require',
            'address|活动地址' => 'require',
            'limit_count|人数限制' => 'require',
            'limit_age|年龄限制' => 'require',
            'cost|活动费用' => 'require',
            'status|状态' => 'noRequire',
        ]);

        $result = $this->activityService->update($param, $id);

        return $this->response->success($result);
    }

    public function destroy(Request $request)
    {
        $id = $request->input('id');
        $result = $this->activityService->delete($id);

        return $this->response->success($result);
    }

    public function setStatus(Request $request)
    {
        $param = $this->validationParameter([
            'id|id' => 'require',
            'status|状态' => 'require',
        ]);

        $result = $this->activityService->setStatus($param);

        return $this->response->success($result);

    }
}
